<?php

declare (strict_types=1);

namespace catchAdmin\monitor\command;

use think\App;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use catcher\Code;

use catcher\platform\AmazonSpService;
use catcher\platform\EbayService;
use catcher\platform\OpenCartService;
use catcher\platform\OverstockService;
use catcher\platform\ShopifyService;
use catcher\platform\WalmartService;
use catcher\platform\WayfairService;
use catcher\platform\HouzzService;

class SyncOrderCommand extends Command
{
    protected $pid;

    protected function configure()
    {
        // 指令配置
        $this->setName('catch:syncOrder')
            ->setDescription('get sync order online list');
    }

    protected function execute(Input $input, Output $output)
    {
        try {
            $this->executeCommand();
        } catch (\Exception $e) {
            Log::error('SyncOrderSchedule Error Line:' . $e->getLine());
            Log::error('SyncOrderSchedule Error Code:' . $e->getCode());
            Log::error('SyncOrderSchedule Error Message:' . $e->getMessage());
            throw new \Exception($e->getMessage());
        }
    }

    /**
     * 执行 command
     *
     * @time 2021年04月28日
     * @return void
     */
    protected function executeCommand()
    {
        $platforms = [
            Code::AMAZON,Code::EBAY,Code::OPENCART,Code::OVERSTOCK,Code::SHOPIFY,Code::WALMART,Code::WAYFAIR,Code::HOUZZ
        ];
        // 同步orderTemp的订单到ERP系统的order
        foreach ($platforms as $val){
            switch ($val){
                case Code::AMAZON:
                    App(AmazonSpService::class)->syncOrderByAccount([$val]);
                    break;
                case Code::EBAY:
                    App(EbayService::class)->syncOrderByAccount([$val]);
                    break;
                case Code::OPENCART:
                    App(OpenCartService::class)->syncOrderByAccount([$val]);
                    break;
                case Code::OVERSTOCK:
                    App(OverstockService::class)->syncOrderByAccount([$val]);
                    break;
                case Code::SHOPIFY:
                    App(ShopifyService::class)->syncOrderByAccount([$val]);
                    break;
                case Code::WALMART:
                    App(WalmartService::class)->syncOrderByAccount([$val]);
                    break;
                case Code::WAYFAIR:
                    App(WayfairService::class)->syncOrderByAccount([$val]);
                    break;
                case Code::HOUZZ:
                    App(HouzzService::class)->syncOrderByAccount([$val]);
                    break;
            }
        }
    }

}
